<!DOCTYPE html>
<html>
  <head>
    <title>My First Extension</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <button id="start">222</button>
    <script src="./popup.js"></script>

    <script>
      // 按钮点击事件监听器
      document.addEventListener("click", () => {
        const startButton = document.getElementById("start");
        console.log("startButton", startButton);
        if (startButton) {
          startButton.addEventListener("click", async () => {
            try {
              // 获取当前活动标签页
              const [tab] = await chrome.tabs.query({
                active: true,
                currentWindow: true,
              });

              // 将start函数注入到当前标签页执行
              await chrome.scripting.executeScript({
                target: { tabId: tab.id },
                function: start,
              });
              console.log("脚本已成功注入到当前标签页");
            } catch (error) {
              console.error("执行脚本时出错:", error);
            }
          });
        }
      });
    </script>
  </body>
</html>
